<?php  
$pPageIsPublic = false;
include '../_common.php';
	
$_SESSION["m1"]	= "content";
$_SESSION["m2"] = 'category-list';

$pTitle  = 'New Neighborhoods';
$pButton = 'Save';
$action  = 'add';
$id 	 = intval($_REQUEST['id']);
$seo	 = NULL;


$objCat = new Category();
$objCat ->setUid($id);
if ($objCat ->load()) {
	$pTitle  = 'Edit Neighborhoods';
	$pButton = 'Update';
	$action  = 'edit';
	//$seo = json_decode($objCat ->seo);
	
	if ($_GET['action']=='del') {
		$objCat ->removeFile('var1');
		$message = "Picture has been removed.";  
	}
}

if (isset($_POST['submit'])) {
	$objCat ->setAuto($_POST);
	$objCat ->uploadFile('ifile', 'var1');
	//$objCat ->seo = arr2json($_POST, array('metaTitle', 'metaDescription', 'metaKeyword', 'friendlyUrl'));
	if ($_POST['action'] == 'edit') {
		$objCat ->getConnection();
		$objCat ->setUid($id);
		$objCat ->update();
		Tzn::redirect('category-list.php', 'Neighborhoods has been updated.');
	} elseif ($_POST['action'] == 'add') {
		$objCat ->add();
		Tzn::redirect('category-list.php', 'Neighborhoods has been added.');
	}
}
?>
<?php include("header.php"); ?>
<script type="text/javascript">
$(document).ready(function(){
	$('#frmMain').validate();	
});
</script>
<?php include("sidebar.php"); ?>
<ul id="subnav" >
	<li ><a class="back" href="category-list.php" > Back </a></li>
	<li class="noborder" >
		<a class="add" href="category-add.php" > Add a New Neighborhoods </a>
	</li>
</ul>
<div id="list">
<h2> <?php echo $pTitle;?> </h2>  
<form action="" method="post" name = "frmMain" id = "frmMain" enctype="multipart/form-data"  >
<fieldset><legend> General Info </legend>
	<table cellpadding="0" cellspacing="0" class="table-form"  >
		<tr>
			<th>Title: </th>
					<td><?php $objCat ->qText('title', '', 'width:548px', 'class="required"');?></td>
				</tr>
				<tr>
					<th>Picture: </th>
					<td><?php $objCat ->pFile('ifile', "{$_SERVER['PHP_SELF']}?id={$objCat ->id}&action=del", 'var1') ?></td>
				</tr>
				<tr>
				<tr>
					<th>Status: </th>
					<td><?php $objCat ->arrayToSelect($objCat ->_arrStatus, 'status', $objCat ->status, false, 'width:100px', '');?></td>
				</tr>
			</table>
	</fieldset>
	<div style="margin-top:10px">
		<input type="hidden" name="id" value="<?php echo $id; ?>" />
		<input type="hidden" name="action" value="<?php echo $action; ?>" />
                <input type="submit" name="submit"  value="<?php echo $pButton; ?>" /> &nbsp; <input type="reset" value="Cancel" onClick="window.location.href='category-list.php'" />
            </div>
            </form>
</div>
<?php include("footer.php"); ?>